<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="author" content="wangbo">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    [v-model=mg] {
      color: red
    }
  </style>
</head>

<body>
  <input type="text" id="txt" v-model="mg" />
  <span id="sp" v-txt="person.mg"></span>

  <script>

    var txt = document.querySelector("#txt")

    const person = {
      name: 'zzz',
      mg: 185
    }
    const proxy = new Proxy(person, {
      get (target, propKey) {// 目标对象  访问的属性名
        console.log(target, propKey); // {  } , name
        return Reflect.get (target, propKey)
      },
      set (target,propKey,newVal) {//监视对象设置属性的过程
        
        sp = document.querySelector(`[v-txt='person.${propKey}']`)
        // 当obj.msg被赋值时 同时设置给 input/span
        txt.value = newVal
        sp.innerText = newVal
        Reflect.set(target, propKey, newVal);
      }
    })


    // txt.dispatchEvent("") 
    // 监听文本框的改变 当文本框输入内容时 改变obj.msg
    txt.addEventListener('keyup', function (event) {
      proxy.mg = event.target.value
    })
  </script>
</body>

</html>